<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 100.00% 
    var findMaxAverage = function(nums, k) {
        const len = nums.length;
        let curSum = 0;
        for(let i=0; i<k; i++){
            curSum += nums[i];
        }
        let maxSum = curSum;
        for(let i=k; i<len; i++){
            curSum = curSum+nums[i]-nums[i-k];
            maxSum = Math.max(maxSum, curSum);
        }
        return maxSum/k;
    };
    let nums = [4,2,1,3,3], k = 2;
    console.log(findMaxAverage(nums, k));
    
</script>
</html>